# ferreus_orbit Plugins for HPE "DL385 Gen10 Plus"

fo_get_sorted_name(){
  local card=$(echo $DEVPATH | cut -d/ -f6)
  local target=$(echo $DEVPATH | cut -d/ -f9)
  # We expect here 2 SATA SSDs and 12 SAS HDD
  if [ "${card}" = "ata7" ] && [ "${target}" = "6:0:0:0" ]; then
    local disk="sda"
    local id=0
  elif [ "${card}" = "ata8" ] && [ "${target}" = "7:0:0:0" ]; then
    local disk="sdb"
    local id=1
  elif   [ "${card}" = "host8" ] ; then
    local sc=$(echo "${DEVPATH}" | cut -d/ -f12)
    local box=$(grep "\[${sc}\]"  /sys/class/scsi_generic/sg*/device/path_info | awk '{print $6}')
    local id=$(grep "\[${sc}\]"  /sys/class/scsi_generic/sg*/device/path_info | awk '{print $8}')
    let "num = ((box - 1) * 4) + id + 1"
    local disk=sd$(fo_get_dev_letter ${num})
  fi
  if [ "$USE_FO_NAME" -lt 1 ]; then
    echo $disk
    exit 0
  else
    echo "Box${box}-Disk${id}"
    exit 0
  fi
}

fo_get_did(){
  local card=$(echo $DEVPATH | cut -d/ -f6)
  local target=$(echo $DEVPATH | cut -d/ -f9)
  # We expect here 2 SATA SSDs and 12 SAS HDD
  if [ "${card}" = "ata7" ] && [ "${target}" = "6:0:0:0" ]; then
    local id=0
  elif [ "${card}" = "ata8" ] && [ "${target}" = "7:0:0:0" ]; then
    local id=1
  elif   [ "${card}" = "host8" ] ; then
    local sc=$(echo "${DEVPATH}" | cut -d/ -f12)
    local box=$(grep "\[${sc}\]"  /sys/class/scsi_generic/sg*/device/path_info | awk '{print $6}')
    local num=$(grep "\[${sc}\]"  /sys/class/scsi_generic/sg*/device/path_info | awk '{print $8}')
    let "id = ((box - 1) * 4) + id + 1"
  fi
  echo $id
}

fo_check_raid(){
  false
}

fo_build_dispo(){
  if [ "$USE_FO_NAME" -ne 1 ]; then
    FO_DISPOSITION=$(printf "${FO_DISPOSITION}"|sed "s/{Disk0}/{sda}/")
    FO_DISPOSITION=$(printf "${FO_DISPOSITION}"|sed "s/{SN_Disk0}/{SN_sda}/")
    FO_DISPOSITION=$(printf "${FO_DISPOSITION}"|sed "s/{Disk1}/{sdb}/")
    FO_DISPOSITION=$(printf "${FO_DISPOSITION}"|sed "s/{SN_Disk1}/{SN_sdb}/")
  fi
 local cpt=2
  for b in 1 2 3; do
    local box=${FO_BOX_DISPOSITION}
    box=$(printf "${box}"|sed "s/{BOX}/${b}/g")
    if [ "$USE_FO_NAME" -ne 1 ]; then
      for i in $(seq 1 4);do
        box=$(printf "${box}"|sed "s/{Box${b}-Disk${i}}/{sd$(fo_get_dev_letter ${cpt})}/g")
        box=$(printf "${box}"|sed "s/{SN_Box${b}-Disk${i}}/{SN_sd$(fo_get_dev_letter ${cpt})}/g")
        let "cpt = cpt + 1"
      done
      fi
    FO_DISPOSITION=$(printf "${FO_DISPOSITION}"|sed "s/{BOX${b}}/${box}/g")
  done
 }

FO_BOX_DISPOSITION="| Box {BOX} |{Box{BOX}-Disk1}|{Box{BOX}-Disk2}|{Box{BOX}-Disk3}|{Box{BOX}-Disk4}|\
{new_line}|       |{SN_Box{BOX}-Disk1}|{SN_Box{BOX}-Disk2}|{SN_Box{BOX}-Disk3}|{SN_Box{BOX}-Disk4}|"

FO_DISPOSITION="""
HDD disposition (Front Panel)
__________{UNDERSCORE}___{UNDERSCORE}___{UNDERSCORE}___{UNDERSCORE}__
{BOX1}
|-------|-{MINUS}-|-{MINUS}-|-{MINUS}-|-{MINUS}-|
{BOX2}
|-------|-{MINUS}-|-{MINUS}-|-{MINUS}-|-{MINUS}-|
{BOX3}
¯¯¯¯¯¯¯¯¯¯{HIGHER}¯¯¯{HIGHER}¯¯¯{HIGHER}¯¯¯{HIGHER}¯¯

HDD disposition (Rear Panel):
__{UNDERSCORE}__
|{Disk0}|
|{SN_Disk0}|
|-{MINUS}-|
|{Disk1}|
|{SN_Disk1}|
¯¯{HIGHER}¯¯
"""
 